// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using System;
using System.Linq;
using Elastic.Clients.Elasticsearch.Serialization;

namespace Elastic.Clients.Elasticsearch.Xpack.Json;

public sealed partial class EqlFeaturesKeysConverter : System.Text.Json.Serialization.JsonConverter<Elastic.Clients.Elasticsearch.Xpack.EqlFeaturesKeys>
{
	private static readonly System.Text.Json.JsonEncodedText PropJoinKeysFiveOrMore = System.Text.Json.JsonEncodedText.Encode("join_keys_five_or_more");
	private static readonly System.Text.Json.JsonEncodedText PropJoinKeysFour = System.Text.Json.JsonEncodedText.Encode("join_keys_four");
	private static readonly System.Text.Json.JsonEncodedText PropJoinKeysOne = System.Text.Json.JsonEncodedText.Encode("join_keys_one");
	private static readonly System.Text.Json.JsonEncodedText PropJoinKeysThree = System.Text.Json.JsonEncodedText.Encode("join_keys_three");
	private static readonly System.Text.Json.JsonEncodedText PropJoinKeysTwo = System.Text.Json.JsonEncodedText.Encode("join_keys_two");

	public override Elastic.Clients.Elasticsearch.Xpack.EqlFeaturesKeys Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
	{
		reader.ValidateToken(System.Text.Json.JsonTokenType.StartObject);
		LocalJsonValue<int> propJoinKeysFiveOrMore = default;
		LocalJsonValue<int> propJoinKeysFour = default;
		LocalJsonValue<int> propJoinKeysOne = default;
		LocalJsonValue<int> propJoinKeysThree = default;
		LocalJsonValue<int> propJoinKeysTwo = default;
		while (reader.Read() && reader.TokenType is System.Text.Json.JsonTokenType.PropertyName)
		{
			if (propJoinKeysFiveOrMore.TryReadProperty(ref reader, options, PropJoinKeysFiveOrMore, null))
			{
				continue;
			}

			if (propJoinKeysFour.TryReadProperty(ref reader, options, PropJoinKeysFour, null))
			{
				continue;
			}

			if (propJoinKeysOne.TryReadProperty(ref reader, options, PropJoinKeysOne, null))
			{
				continue;
			}

			if (propJoinKeysThree.TryReadProperty(ref reader, options, PropJoinKeysThree, null))
			{
				continue;
			}

			if (propJoinKeysTwo.TryReadProperty(ref reader, options, PropJoinKeysTwo, null))
			{
				continue;
			}

			if (options.UnmappedMemberHandling is System.Text.Json.Serialization.JsonUnmappedMemberHandling.Skip)
			{
				reader.Skip();
				continue;
			}

			throw new System.Text.Json.JsonException($"Unknown JSON property '{reader.GetString()}' for type '{typeToConvert.Name}'.");
		}

		reader.ValidateToken(System.Text.Json.JsonTokenType.EndObject);
		return new Elastic.Clients.Elasticsearch.Xpack.EqlFeaturesKeys(Elastic.Clients.Elasticsearch.Serialization.JsonConstructorSentinel.Instance)
		{
			JoinKeysFiveOrMore = propJoinKeysFiveOrMore.Value,
			JoinKeysFour = propJoinKeysFour.Value,
			JoinKeysOne = propJoinKeysOne.Value,
			JoinKeysThree = propJoinKeysThree.Value,
			JoinKeysTwo = propJoinKeysTwo.Value
		};
	}

	public override void Write(System.Text.Json.Utf8JsonWriter writer, Elastic.Clients.Elasticsearch.Xpack.EqlFeaturesKeys value, System.Text.Json.JsonSerializerOptions options)
	{
		writer.WriteStartObject();
		writer.WriteProperty(options, PropJoinKeysFiveOrMore, value.JoinKeysFiveOrMore, null, null);
		writer.WriteProperty(options, PropJoinKeysFour, value.JoinKeysFour, null, null);
		writer.WriteProperty(options, PropJoinKeysOne, value.JoinKeysOne, null, null);
		writer.WriteProperty(options, PropJoinKeysThree, value.JoinKeysThree, null, null);
		writer.WriteProperty(options, PropJoinKeysTwo, value.JoinKeysTwo, null, null);
		writer.WriteEndObject();
	}
}